﻿using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Collections.Generic;
using System.Console;
using System.Linq;
using ExprParser;
using Nemerle.Peg;

module Program
{
  Main() : void
  {
    def parser = ExprParser();
    mutable text = "2 + -5";

    WriteLine(text);
    do
    {
      try
      {
        match (parser.Parse(text))
        {
          | Some(ast) =>
            WriteLine(ast);

          | None => 
            def (pos, rules) = parser.GetMaxRollbackPosAndNames();
            WriteLine(string(' ', pos) + "^");
            WriteLine($"Expected: ..$rules");
        }
      }
      catch
      {
        | ex => WriteLine(ex);
      }

      text = Console.ReadLine();
    }
    while (text != "");
  }
}